package com.silverhaze.diamond.common.entity;


import com.silverhaze.commons.db.datasource.ObjectEntity;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * Created by Ivan Babanin (06.07.2007 20:26:01)
 * This part of code is strictly confidential.
 * © Magnificent Software Inc.
 */
@Entity()
@Table(name = "services")
public class Service extends ObjectEntity {
    private static final long serialVersionUID = 2689127L;

    @Basic()
    private long orderId;

    @Basic()
    private Date dateProduce;

    @Basic()
    private Date dateService;

    @Basic()
    private String techNames;

    @Basic()
    private String modelName;

    @Basic()
    private String techModelName;

    @ManyToOne(targetEntity = Customer.class)
    private Customer owner;

    @ManyToOne(targetEntity = SystemUser.class)
    private SystemUser systemUser;

    @Basic()
    private String serialNumber;

    @Basic()
    private String guarantyId;

    @Basic()
    private String completeness;

    @Basic()
    private String ownerDefect;

    @Basic()
    private String masterDefect;

    @Basic()
    private String stampState;  // Состояние пломбы

    // Repaired
    @Basic()
    private double cost;

    @OneToMany(targetEntity = UsedDetail.class, fetch = FetchType.EAGER)
    private Set<UsedDetail> usedDetailes;

    @OneToMany(targetEntity = BrokenDetail.class, fetch = FetchType.EAGER)
    private Set<BrokenDetail> brokenDetailes;

    @Basic()
    private boolean serviceComplete;

    @Basic()
    private String serviceType;

    @Basic()
    private boolean repair;

    @Basic()
    private Date serviceCompleteDate;

    @Basic()
    private long barcodeId;

    // Client take stuff
    private Date clientTaskStuffDate;

    public long getOrderId() {
        return orderId;
    }

    public void setOrderId(long orderId) {
        this.orderId = orderId;
    }

    public String getServiceType() {
        return serviceType;
    }

    public void setServiceType(String serviceType) {
        this.serviceType = serviceType;
    }

    public Date getDateProduce() {
        return dateProduce;
    }

    public void setDateProduce(Date dateProduce) {
        this.dateProduce = dateProduce;
    }

    public Date getDateService() {
        return dateService;
    }

    public void setDateService(Date dateService) {
        this.dateService = dateService;
    }

    public String getTechNames() {
        return techNames;
    }

    public void setTechNames(String techNames) {
        this.techNames = techNames;
    }

    public String getModelName() {
        return modelName;
    }

    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public String getTechModelName() {
        return techModelName;
    }

    public void setTechModelName(String techModelName) {
        this.techModelName = techModelName;
    }

    public Customer getOwner() {
        return owner;
    }

    public void setOwner(Customer owner) {
        this.owner = owner;
    }

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    public String getSerialNumber() {
        return serialNumber;
    }

    public void setSerialNumber(String serialNumber) {
        this.serialNumber = serialNumber;
    }

    public String getGuarantyId() {
        return guarantyId;
    }

    public void setGuarantyId(String guarantyId) {
        this.guarantyId = guarantyId;
    }

    public String getCompleteness() {
        return completeness;
    }

    public void setCompleteness(String completeness) {
        this.completeness = completeness;
    }

    public String getOwnerDefect() {
        return ownerDefect;
    }

    public void setOwnerDefect(String ownerDefect) {
        this.ownerDefect = ownerDefect;
    }

    public String getMasterDefect() {
        return masterDefect;
    }

    public void setMasterDefect(String masterDefect) {
        this.masterDefect = masterDefect;
    }

    public String getStampState() {
        return stampState;
    }

    public void setStampState(String stampState) {
        this.stampState = stampState;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public Set<UsedDetail> getUsedDetailes() {
        return usedDetailes;
    }

    public void setUsedDetailes(Set<UsedDetail> usedDetailes) {
        this.usedDetailes = usedDetailes;
    }

    public Set<BrokenDetail> getBrokenDetailes() {
        return brokenDetailes;
    }

    public void setBrokenDetailes(Set<BrokenDetail> brokenDetailes) {
        this.brokenDetailes = brokenDetailes;
    }

    public boolean isServiceComplete() {
        return serviceComplete;
    }

    public void setServiceComplete(boolean serviceComplete) {
        this.serviceComplete = serviceComplete;
    }

    public boolean isRepair() {
        return repair;
    }

    public void setRepair(boolean repair) {
        this.repair = repair;
    }

    public Date getServiceCompleteDate() {
        return serviceCompleteDate;
    }

    public void setServiceCompleteDate(Date serviceCompleteDate) {
        this.serviceCompleteDate = serviceCompleteDate;
    }

    @Basic()
    public Date getClientTaskStuffDate() {
        return clientTaskStuffDate;
    }

    public void setClientTaskStuffDate(Date clientTaskStuffDate) {
        this.clientTaskStuffDate = clientTaskStuffDate;
    }

    public Service copyService() {
        Service service = new Service();

        service.setRepair(isRepair());
        service.setTechNames(getTechNames());
        service.setModelName(getModelName());
        service.setTechModelName(getTechModelName());
        service.setSerialNumber(getSerialNumber());
        service.setDateProduce(getDateProduce());
        service.setStampState(getStampState());
        service.setGuarantyId(getGuarantyId());
        service.setCompleteness(getCompleteness());
        service.setOwnerDefect(getOwnerDefect());
        service.setMasterDefect(getMasterDefect());

        service.setOwner(getOwner());

        return service;
    }

    @Transient()
    public boolean isClientTookStuff() {
        return clientTaskStuffDate != null;
    }

    public long getBarcodeId() {
        return barcodeId;
    }

    public void setBarcodeId(long barcodeId) {
        this.barcodeId = barcodeId;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Service)) return false;

        Service service = (Service) o;

        if (Double.compare(service.cost, cost) != 0) return false;
        if (repair != service.repair) return false;
        if (serviceComplete != service.serviceComplete) return false;
        if (brokenDetailes != null ? !brokenDetailes.equals(service.brokenDetailes) : service.brokenDetailes != null)
            return false;
        if (clientTaskStuffDate != null ? !clientTaskStuffDate.equals(service.clientTaskStuffDate) : service.clientTaskStuffDate != null)
            return false;
        if (completeness != null ? !completeness.equals(service.completeness) : service.completeness != null)
            return false;
        if (dateProduce != null ? !dateProduce.equals(service.dateProduce) : service.dateProduce != null) return false;
        if (dateService != null ? !dateService.equals(service.dateService) : service.dateService != null) return false;
        if (guarantyId != null ? !guarantyId.equals(service.guarantyId) : service.guarantyId != null) return false;
        if (masterDefect != null ? !masterDefect.equals(service.masterDefect) : service.masterDefect != null)
            return false;
        if (modelName != null ? !modelName.equals(service.modelName) : service.modelName != null) return false;
        if (owner != null ? !owner.equals(service.owner) : service.owner != null) return false;
        if (ownerDefect != null ? !ownerDefect.equals(service.ownerDefect) : service.ownerDefect != null) return false;
        if (serialNumber != null ? !serialNumber.equals(service.serialNumber) : service.serialNumber != null)
            return false;
        if (serviceCompleteDate != null ? !serviceCompleteDate.equals(service.serviceCompleteDate) : service.serviceCompleteDate != null)
            return false;
        if (serviceType != null ? !serviceType.equals(service.serviceType) : service.serviceType != null) return false;
        if (stampState != null ? !stampState.equals(service.stampState) : service.stampState != null) return false;
        if (techModelName != null ? !techModelName.equals(service.techModelName) : service.techModelName != null)
            return false;
        if (techNames != null ? !techNames.equals(service.techNames) : service.techNames != null) return false;
        if (usedDetailes != null ? !usedDetailes.equals(service.usedDetailes) : service.usedDetailes != null)
            return false;
        if (systemUser != null ? !systemUser.equals(service.systemUser) : service.systemUser != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        long temp;
        result = (dateProduce != null ? dateProduce.hashCode() : 0);
        result = 31 * result + (dateService != null ? dateService.hashCode() : 0);
        result = 31 * result + (techNames != null ? techNames.hashCode() : 0);
        result = 31 * result + (modelName != null ? modelName.hashCode() : 0);
        result = 31 * result + (techModelName != null ? techModelName.hashCode() : 0);
        result = 31 * result + (owner != null ? owner.hashCode() : 0);
        result = 31 * result + (systemUser != null ? systemUser.hashCode() : 0);
        result = 31 * result + (serialNumber != null ? serialNumber.hashCode() : 0);
        result = 31 * result + (guarantyId != null ? guarantyId.hashCode() : 0);
        result = 31 * result + (completeness != null ? completeness.hashCode() : 0);
        result = 31 * result + (ownerDefect != null ? ownerDefect.hashCode() : 0);
        result = 31 * result + (masterDefect != null ? masterDefect.hashCode() : 0);
        result = 31 * result + (stampState != null ? stampState.hashCode() : 0);
        temp = cost != +0.0d ? Double.doubleToLongBits(cost) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (usedDetailes != null ? usedDetailes.hashCode() : 0);
        result = 31 * result + (brokenDetailes != null ? brokenDetailes.hashCode() : 0);
        result = 31 * result + (serviceComplete ? 1 : 0);
        result = 31 * result + (serviceType != null ? serviceType.hashCode() : 0);
        result = 31 * result + (repair ? 1 : 0);
        result = 31 * result + (serviceCompleteDate != null ? serviceCompleteDate.hashCode() : 0);
        result = 31 * result + (clientTaskStuffDate != null ? clientTaskStuffDate.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Service{" +
                "dateProduce=" + dateProduce +
                ", dateService=" + dateService +
                ", techNames='" + techNames + '\'' +
                ", modelName='" + modelName + '\'' +
                ", techModelName='" + techModelName + '\'' +
                ", owner=" + owner +
                ", systemUser=" + systemUser +
                ", serialNumber='" + serialNumber + '\'' +
                ", guarantyId='" + guarantyId + '\'' +
                ", completeness='" + completeness + '\'' +
                ", ownerDefect='" + ownerDefect + '\'' +
                ", masterDefect='" + masterDefect + '\'' +
                ", stampState='" + stampState + '\'' +
                ", cost=" + cost +
                ", usedDetailes=" + usedDetailes +
                ", brokenDetailes=" + brokenDetailes +
                ", serviceComplete=" + serviceComplete +
                ", serviceType='" + serviceType + '\'' +
                ", repair=" + repair +
                ", serviceCompleteDate=" + serviceCompleteDate +
                ", clientTaskStuffDate=" + clientTaskStuffDate +
                '}';
    }
}

